<template>
    <div class="listDiv pd20">
        <div class="searchDiv">
            <el-form class="searchLeft" ref="serform" :model="obj.req" label-position="top">
                <el-form-item class="mr20 mb10">
                    <span class="btn add" @click="add">添加人员</span>
                </el-form-item>
                <el-form-item class="serlabelB mr20 mb10" label="人员名称：" prop="key">
                    <el-input v-model="obj.req.key" placeholder="请输入人员名称" class="search_key" clearable  />
                </el-form-item>
                <span class="btn search mb10 mr5" @click="obj.req.currentpage=1;init()">查询</span>
                <span class="btn refresh mb10" @click="proxy.$refs['serform'].resetFields();init()">重置</span>
            </el-form>
        </div>
        <div class="table" id="tb">
            <ul class="head">
                <li class="liflex">姓名</li>
                <li class="liflex flex-center">最后登录时间</li>
                <li class="liaction liflex">操作</li>
            </ul>
            <div class="body">
                <ul v-for="x in obj.ary" :key="x">
                    <li class="liflex flex-center">{{x.name}}</li>
                    <li class="liflex flex-center">{{x.last_login_time}}</li>
                    <li class="liaction liflex flex-center">
                        <u @click.prevent="edit(x)">编辑</u>
                        <DelConfirm @yesClick="del(x)" />
                    </li>
                </ul>
            </div>
        </div>
        <ElConfigProvider :locale="locale">
            <el-pagination layout="total, prev, pager, next, jumper" background :total="obj.req.count" :page-size="obj.req.pagesize" v-model:currentPage="obj.req.currentpage" @current-change="init()" />
        </ElConfigProvider>
    </div>
</template>

<script setup>
    import { reactive,getCurrentInstance,onActivated } from 'vue'
    import DelConfirm from '@/components/del_confirm.vue'

    import locale from "element-plus/es/locale/lang/zh-cn";
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        ary:[],
        req:{
            currentpage: 1,
            pagesize: 10,
            count: 0,
            key: "",
        }
    })

    onActivated(async()=>{
        obj.companys = await proxy.$setting.getdepts()
        init()
    })

    let init = () => {
        proxy.$ajax({
            url: '/manager/user/list',
            data: obj.req,
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                obj.ary = d.msg.list
                obj.req.count = d.msg.count
            }
        }).catch(() => { })
    }

    let add = () => {
        proxy.routerPushMixin("/userEdit",{}
    )
    }
    let edit = x => {
        proxy.routerPushMixin("/userEdit",{id:x.userid})
    }

    let del = x => {
        proxy.$ajax({
            url: '/manager/user/delete',
            data: { userid: x.userid },
            bfLoading: true
        }).then(d => {
            if(d.success){
                proxy.elMessageMixin("删除成功", 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
</script>

<style scoped>
</style>